package com.hzdl.car.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzdl.car.bean.Car;
import com.hzdl.car.bean.Customer;
import com.hzdl.car.mapper.CarMapper;
import com.hzdl.car.service.CarService;
import com.hzdl.car.vo.CarVo;
import com.hzdl.car.vo.CustomerVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional
@Service
public class CarServiceImpl implements CarService {
    @Resource
    private CarMapper carMapper;

    @Override
    public PageInfo<Car> findCar(CarVo carVo) {
        PageHelper.startPage(carVo.getPage(),carVo.getLimit());
        List<Car> list=carMapper.findCar(carVo);
        PageInfo<Car> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int delCar(CarVo carVo) {
        return carMapper.delCar(carVo);
    }

    @Override
    public int addCar(CarVo carVo) {
        return carMapper.addCar(carVo);
    }

    @Override
    public int updateCar(CarVo carVo) {
        return carMapper.updateCar(carVo);
    }

    @Override
    public int carDelChk(String[] ids) {
        int row=0;
        for (String i:ids){
            CarVo carVo=new CarVo();
            carVo.setCarNumber(i);
            row+=carMapper.delCar(carVo);
        }
        return row;
    }

    @Override
    public int carIsRent(CarVo carVo) {
        return carMapper.carIsRent(carVo);
    }

    @Override
    public Car findCarByNum(String CarNum) {
        return carMapper.findCarByNum(CarNum);
    }
}
